(function($){
	$.crbn = {
		calculate: function(event){
			event.preventDefault();
			var totalAmt = 0;
			$('#row tr').each(function(){
				var row = $(this);
				var quan = row.find('td .quant').val();
				var price = row.find('td .price').val();
				var total = row.find('td .total');
				var sum = quan*price;
				if(!isNaN(sum)){
					total.val(sum);
					totalAmt += sum;
				}
			});
			
			$('#totalAmt').val(totalAmt);
		},
		
		deleteHist: function(){
			event.preventDefault();
			var id = this.id;
			$.ajax("/services/deleteHistory?historyId=" + id);
			$(this).parent().parent().hide();
		},
		
		init: function(){
			$('#calculateBtn').bind('click', $$.calculate);
			$('.deleteBtn').bind('click', $$.deleteHist);
		}
	};
})(jQuery);

window.crbn = window.$$ = jQuery.crbn;

$(document).ready(function() {
	$$.init();
});